//
//  TPCityHeader.m
//  Tripvi
//
//  Created by xiaowuxiaowu on 2017/5/10.
//  Copyright © 2017年 xiaowuxiaowu. All rights reserved.
//

#import "TPCityHeader.h"

@interface TPCityHeader()<UISearchBarDelegate>

@property (nonatomic,strong)UILabel *cityLabel;
@property (nonatomic,strong,readwrite)UISearchBar *searchBar;

@end

@implementation TPCityHeader
-(instancetype)initWithFrame:(CGRect)frame{
   
    if(self = [super initWithFrame:frame]){
     
        [self setup];
    }
    
    return self;
}

-(void)setup{
    
    UILabel *titleLabel = [UILabel initWithFrame:CGRectZero font:fontSystemOfSize(15) color:TPBlack_999999 aligment:NSTextAlignmentLeft];
    titleLabel.backgroundColor = TP_COLOR_245;
    titleLabel.text = @"  当前定位";
    [self addSubview:titleLabel];
    
    _cityLabel = [UILabel initWithFrame:CGRectZero font:fontSystemOfSize(16) color:TPBlack_666666 aligment:NSTextAlignmentRight];
    _cityLabel.backgroundColor = [UIColor clearColor];
    RAC(_cityLabel,text) = RACObserve([XWCommon shareAppDelegate], locationCity);
    [self addSubview:_cityLabel];
    
    
    _searchBar = [[UISearchBar alloc]init];
     _searchBar.barTintColor = [UIColor whiteColor];
    [_searchBar tp_setupSearchBarPlaceholder:@"请输入搜索城市"];
    [_searchBar setButtonClickBlock:^(UISearchBar *earchBar) {
        [earchBar resignFirstResponder];
    }];
   
    [self addSubview:_searchBar];
    
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0.0f);
        make.height.mas_equalTo(34.0);
        
    }];
    [_cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-18.0f);
        make.top.height.mas_equalTo(titleLabel);
    }];
    
    [_searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(0);
        make.bottom.mas_equalTo(-10);
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.94);
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    
    
    self.height = 34 + 20.0 + 40.0;

}




@end
